package com.lin.excel.controller;

import com.lin.excel.annotation.Timer;
import com.lin.excel.service.ExcelService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName ExcelController
 * @Description Excel Controller
 * @Author lin
 * @Date 2022/7/21 下午10:58
 * @Version V1.0
 */
@RestController
@Slf4j
@RequestMapping("/excel")
public class ExcelController {
    @Autowired
    private ExcelService excelService;

    // http://localhost:8081/excel/excel/user/张三110
    @GetMapping("/user/{name}")
    @Timer
    public void exportUser(@PathVariable("name") String name, HttpServletResponse response){
        excelService.exportUser(name,response);
    }

    // http://localhost:8081/excel/excel/easypoi/张三110
    @GetMapping("/easypoi/{name}")
    @Timer
    public void easyPoiExportUser(@PathVariable("name") String name, HttpServletRequest request, HttpServletResponse response){
        excelService.easyPoiExportUser(name,request,response);
    }

    // http://localhost:8081/excel/excel/easyexcel/张三110
    @GetMapping("/easyexcel/{name}")
    @Timer
    public void easyExcelExportUser(@PathVariable("name") String name, HttpServletRequest request, HttpServletResponse response){
        excelService.easyExcelExportUser(name,request,response);
    }

}
